package znbkTestPaperLstjt.presenter;

import android.util.Log;

import com.example.lancooznbk.view.base.ILoadPaperView;
import com.lancoo.rxretrofitlibrary.http.HttpManager;
import com.lancoo.rxretrofitlibrary.listener.HttpOnNextListener;

import java.util.List;

import znbkListXtfx.ISystemReviewPresenter;
import znbkTestPaperLstjt.activity.HistoryRecommendQuesPaperActivity;
import znbkTestPaperLstjt.api.HistoryRecommendQuesPaperApi;
import znbkTestPaperLstjt.entity.HistoryRecommendQuesPaperEntity;

/**
 * Created by Administrator on 2018\4\9 0009.
 */

public class HistoryRecommendQuesPaperPresenter implements ISystemReviewPresenter {

    private ILoadPaperView view;

    public HistoryRecommendQuesPaperPresenter(ILoadPaperView view) {
        this.view =  view;
    }

    @Override
    public void getData(boolean isShowLoading) {
        if (isShowLoading) view.showLoading();
        HttpOnNextListener<List<HistoryRecommendQuesPaperEntity>> httpOnNextListener = new HttpOnNextListener<List<HistoryRecommendQuesPaperEntity>>() {

            @Override
            public void onNext(List<HistoryRecommendQuesPaperEntity> historyRecommendQuesPaperEntity) {
                int totalCount = historyRecommendQuesPaperEntity.size();
                Log.e("====totalCount====","==="+totalCount);
                if(totalCount>0){
                    view.hideLoading();
                    view.loadPaperData(historyRecommendQuesPaperEntity);
                }else {
                    view.showNoData("暂无历史推荐题");
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
            }
        };
        HistoryRecommendQuesPaperApi api = new HistoryRecommendQuesPaperApi(httpOnNextListener, (HistoryRecommendQuesPaperActivity)view);
        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(api);
    }

    @Override
    public void getMoreData() {
        getData(false);
    }

    @Override
    public void getDataByStatus(int position) {
        getData(false);
    }

}